package com.jianchi.fsp.generationchildrenarithmetic;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;

import java.util.ArrayList;

import belka.us.androidtoggleswitch.widgets.ToggleSwitch;

public class MainActivity extends AppCompatActivity {

    private ToggleSwitch numberNum;
    private ToggleSwitch createCount;
    private ToggleSwitch calculationMethod;
    private ToggleSwitch resultRange;

    int[] nn = {2,3,4};
    int[] cc = {10,20,50,100};
    String[] cm = {"混合", "加法", "减法"};
    int[] rr = {10,20,50,100};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        numberNum = initToggleSwitch(R.id.numberNum, nn);
        createCount = initToggleSwitch(R.id.createCount, cc);
        calculationMethod = initToggleSwitch(R.id.calculationMethod, cm);
        resultRange = initToggleSwitch(R.id.resultRange, rr);

        numberNum.setCheckedTogglePosition(0);
        createCount.setCheckedTogglePosition(3);
        calculationMethod.setCheckedTogglePosition(0);
        resultRange.setCheckedTogglePosition(3);

        Button bt = (Button) findViewById(R.id.bt_create);
        bt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                GenHelper gen = new GenHelper();
                gen.numberNum = nn[numberNum.getCheckedTogglePosition()];
                gen.createCount = cc[createCount.getCheckedTogglePosition()];
                gen.calculationMethod = cm[calculationMethod.getCheckedTogglePosition()];
                gen.resultRange = rr[resultRange.getCheckedTogglePosition()];

                Intent intent = new Intent(getApplicationContext(), ShowActivity.class);
                Bundle bundle = new Bundle();
                bundle.putSerializable("gen", gen);
                intent.putExtras(bundle);
                startActivity(intent);
            }
        });
    }

    ToggleSwitch initToggleSwitch(int id, int ... msgs){
        ToggleSwitch toggleSwitch = (ToggleSwitch) findViewById(id);
        ArrayList<String> labels = new ArrayList<>();
        for(int s: msgs)
            labels.add(String.valueOf(s));
        toggleSwitch.setLabels(labels);
        return toggleSwitch;
    }
    ToggleSwitch initToggleSwitch(int id, String ... msgs){
        ToggleSwitch toggleSwitch = (ToggleSwitch) findViewById(id);
        ArrayList<String> labels = new ArrayList<>();
        for(String s: msgs)
            labels.add(s);
        toggleSwitch.setLabels(labels);
        return toggleSwitch;
    }
}
